package com.ggh.jinjilive.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.Window;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.cy.dialog.BaseDialog;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.dialog.adapter.LiveShrinkageAdapter;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.mobile.live.ShrinkageMobile;

import java.util.ArrayList;
import java.util.List;

public class LiveShrinkageDialog extends BaseDialog {
    private List<ShrinkageMobile> shrinkageMobileList;
    private LiveShrinkageAdapter liveShrinkageAdapter;
    private RecyclerView rv;

    private boolean playState = false;
    //当前是否在pk中
    private boolean isPk = false;

    public LiveShrinkageDialog(Context context) {
        super(context);
    }

    public LiveShrinkageDialog(Context context, int themeResId) {

        super(context, themeResId);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        contentView(R.layout.dailog_live_shrinkage);
        getWindow().setDimAmount(0f);
        canceledOnTouchOutside(true);
        animType(AnimInType.BOTTOM);
        gravity(Gravity.BOTTOM);
        shrinkageMobileList = new ArrayList<>();
        rv = findViewById(R.id.rv);
        liveShrinkageAdapter = new LiveShrinkageAdapter();
        liveShrinkageAdapter.setAddItemOnClickListener(new AddItemOnClickListener() {
            @Override
            public void onSkipClicked(int position, Object mObject) {
                if(null != addItemOnClickListener){
                    addItemOnClickListener.onSkipClicked(position,mObject);
                }
            }
        });
        rv.setLayoutManager(new GridLayoutManager(getContext(),4));
        rv.setAdapter(liveShrinkageAdapter);
    }

    private AddItemOnClickListener addItemOnClickListener;

    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener) {
        this.addItemOnClickListener = addItemOnClickListener;
    }

    /**
     *
     * @param playState
     */
    public void playState(boolean playState,boolean isPk){
        this.playState = playState;
        //当前是否在pk中
        this.isPk = isPk;
        //加载数据
        setShrinkageMobile();
    }


    /**
     *加载数据
     */
    private void setShrinkageMobile(){
        shrinkageMobileList.clear();
        //美颜
        ShrinkageMobile shrinkageMobile =  new ShrinkageMobile();
        shrinkageMobile.setPicture(R.mipmap.icon_live_beauty);
        shrinkageMobile.setName("美颜");
        shrinkageMobileList.add(shrinkageMobile);
        //切换相机
        ShrinkageMobile shrinkageMobile1 =  new ShrinkageMobile();
        shrinkageMobile1.setPicture(R.mipmap.icon_live_switch_camera);
        shrinkageMobile1.setName("切换相机");
        shrinkageMobileList.add(shrinkageMobile1);
        //闪光灯
        ShrinkageMobile shrinkageMobile2 =  new ShrinkageMobile();
        shrinkageMobile2.setPicture(R.mipmap.icon_live_flashlight);
        shrinkageMobile2.setName("闪光灯");
        shrinkageMobileList.add(shrinkageMobile2);
        //音乐
        ShrinkageMobile shrinkageMobile3 =  new ShrinkageMobile();
        shrinkageMobile3.setPicture(R.mipmap.icon_live_music);
        shrinkageMobile3.setName("音乐");
        shrinkageMobileList.add(shrinkageMobile3);
//        //pk
//        ShrinkageMobile shrinkageMobile4 =  new ShrinkageMobile();
//        shrinkageMobile4.setPicture(R.mipmap.icon_live_pk);
//        if(isPk){
//            shrinkageMobile4.setName("结束pk");
//        }else {
//            shrinkageMobile4.setName("pk");
//        }
//
//        shrinkageMobileList.add(shrinkageMobile4);
        //镜像
        ShrinkageMobile shrinkageMobile5 =  new ShrinkageMobile();
        shrinkageMobile5.setPicture(R.mipmap.icon_live_mirror);
        shrinkageMobile5.setName("观众镜像");
        shrinkageMobileList.add(shrinkageMobile5);
        //播放和暂停直播
        ShrinkageMobile shrinkageMobile6 =  new ShrinkageMobile();
        if(playState){
            shrinkageMobile6.setPicture(R.mipmap.icon_live_suspended);
            shrinkageMobile6.setName("暂停直播");
        }else {
            shrinkageMobile6.setPicture(R.mipmap.icon_live_play);
            shrinkageMobile6.setName("继续直播");
        }
        shrinkageMobileList.add(shrinkageMobile6);
        //
        liveShrinkageAdapter.setAdd(shrinkageMobileList);
    }

    @Override
    public void show() {
        super.show();
        Window window = getWindow();
        //设置弹出位置
        window.setGravity(Gravity.BOTTOM);
        //设置对话框大小
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    }
}
